#!/bin/bash
# 1. 移除旧版本docker
sudo yum remove -y  docker \
                    docker-client \
                    docker-client-latest \
                    docker-common \
                    docker-latest \
                    docker-latest-logrotate \
                    docker-logrotate \
                    docker-engine

# 2. 安装相关软件
sudo yum install -y yum-utils \
                    device-mapper-persistent-data \
                    lvm2 \
                    vim \
                    wget \ 
                    epel-release

# 3. 安装相关源
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

# 4. 缓存生效
sudo yum makecache fast

# 5. 安装Docker
sudo yum install -y docker-ce docker-ce-cli containerd.io

# 6. 启动docker,加入开机启动
sudo systemctl start docker
sudo systemctl enable docker

# 7. 设置镜像加速
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": [
    "https://registry.docker-cn.com",
    "http://hub-mirror.c.163.com",
    "https://docker.mirrors.ustc.edu.cn"
  ]
}
EOF
sudo systemctl restart docker

# 8. 安装Docker-compose
sudo curl -L https://get.daocloud.io/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m) > /usr/local/bin/docker-compose
sudo chmod -R 777 /usr/local/bin/docker-compose